<template>
	<view v-if="pageShow">
		<view class="" style="padding-bottom: 180rpx;" v-if="showMain">
			<u-swiper height= "569rpx" :list="dataAll.images_text" @click="lbtpriview($event,dataAll.images_text)" radius="0" indicator circular></u-swiper>
			<view class="" style="position: relative; top: -30rpx;">
				<!--  -->
				<view class="block  ffffff">
					<view class="sanshier zhonghei fonweight">{{dataAll.name}}</view>
					<view class="flexbetween margin_top2">
						<view class="flexleft ">
							<view class="margin_right1" v-for="item in dataAll.star" :key="item">
								<u-icon name="star-fill" color="#FF9341" size="28"></u-icon>
							</view>
						</view>
						<view class="ershil xiaohei fonweight">{{dataAll.year}}</view>
					</view>
					<view class="flexbetween margin_top2">
						<view class="flexleft">
							<view class="dingwei">
								<view class="sishi fonweight zhonghei dingwei" style="z-index: 1;">{{dataAll.star}}</view>
								<view class="ztxhx"></view>
							</view>
							<view class="xiaohui strongtext ">{{dataAll.comment_num}}评论</view>
						</view>
						<view class="flexright" @click="tzckpj">
							<view class="xiaohui strongtext ">查看全部评论</view>
							<u-icon name="arrow-right" color="#999999"></u-icon>
						</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="">
							<view class="flexleft">
								<view class="margin_right1">
									<u-icon name="phone" color="#969696"></u-icon>
								</view>
								<view class="xiaohei ershil">{{dataAll.mobile}}</view>
							</view>
							<view class="flexleft margin_top">
								<view class="margin_right1">
									<u-icon name="map" color="#969696"></u-icon>
								</view>
								<view class="xiaohei ershil">{{dataAll.detail}}</view>
							</view>
						</view>
						<view class="flexright">
							<view class="margin_right4" @click="callphone(dataAll.mobile)">
								<image class="dhicon" src="../static/images/system/dh.png" mode=""></image>
								<view class="xiaocheng ershil margin_top1 textcenter">电话</view>
							</view>
							<view class="" @click="openlocation">
								<image class="dhicon" src="../static/images/system/dh1.png" mode=""></image>
								<view class="xiaolan ershil margin_top1 textcenter">导航</view>
							</view>
						</view>
					</view>
				</view>
				<view class="ffffff mainpadding margin_top"  @click="show=true" v-if="startime">
					<view class="flexbetween ">
						<view class="flexleft">
							<view class="bigtext zhonghei fonweight margin_right2">{{startime}}</view>
							<view class="smalltext xiaohui margin_right4">{{startweek}}</view>
							<view class="hhbtn flexcenter margin_right4">{{daynum}}晚</view>
							<view class="bigtext zhonghei fonweight margin_right2">{{endtime}}</view>
							<view class="smalltext xiaohui">{{endweek}}</view>
						</view>
						<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
				</view>
				<view class="ffffff mainpadding margin_top"  @click="show=true" v-if="!startime">
					<view class="flexbetween ">
						<view class="bigtext zhonghei fonweight margin_right2">请选择入住日期</view>
						<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
				</view>
				<!--  -->
				<view id="target">
					<view class="ffffff mainpadding  margin_top" v-for="item in dataAll.hotel_type" :key="item.id" @click="tzfjxq(item.id)">
						<view class="flexleft ">
							<view class="fenbox margin_right1">积分抵扣￥{{item.score_price}}</view>
							<view class="huangbox margin_right1" v-show="Number(item.sdyh_price)">首单优惠￥{{item.sdyh_price}}</view>
							<view class="fenbox" v-show="Number(item.activity_price)">活动优惠￥{{item.activity_price}}</view>
						</view>
						<view class="flexbetween margin_top2">
							<image class="tupian" :src="item.image_text" mode=""></image>
							<view class="" style="width: 68%;">
								<view class="zhonghei sanshier fonweight ">{{item.name}}</view>
								<view class="xiaohui ershil margin_top2 yhxk">
									<text v-for="(value,key,index) in item.attr_text" :key="key">{{key}}-{{value}}</text>
								</view>
								
								<view class="flexbottom1 margin_top4" style="justify-content: flex-end;">
									<view class="xiaocheng bigtext fonweight margin_right1">￥{{item.salesprice}}
										<text class="xiaohui strongtext  ">/晚</text>
									</view>
									<image class="zaxd" src="../static/images/system/zxd.png" mode="" @click.stop="goYuDing(item.id)"></image>
								</view>
							</view>
						</view>
						
					</view>
				</view>
				<view class="ffffff mainpadding margin_top">
					<u-parse :content="dataAll.attention"></u-parse>
				</view>
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding flexbetween">
			<view class="flexleft">
				<view class="margin_right" @click="collect(listid)">
					<u-icon name="star" color="#666666" size="28" v-if="dataAll.is_collect==0"></u-icon>
					<u-icon name="star-fill" color="#FF9341" size="28" v-if="dataAll.is_collect==1"></u-icon>
					<view class="zhonghei ershil margin_top1 ">收藏</view>
				</view>
				<!-- <button class="dibubox" open-type="contact" bindcontact="handleContact" session-from="sessionFrom"
					hover-class="none">
					<view class="">
						<u-icon name="kefu-ermai" color="#666666" size="28"></u-icon>
						<view class="zhonghei ershil margin_top1 ">客服</view>
					</view>
				</button> -->
				<view class="" @click="contactkf('shop'+dataAll.shop_id,'2')">
					<u-icon name="kefu-ermai" color="#666666" size="28"></u-icon>
					<view class="zhonghei ershil margin_top1 ">客服</view>
				</view>
			</view>
			<view class="huabtn flexcenter" @click="gundong()">全看全部房型</view>
		</view>
		<u-calendar color="#FF9341" startText="入住" endText="离店" :mode="mode" confirmText="确认选择"
			confirmDisabledText="确认选择" :show="show" @confirm="confirm" @close="show=false"></u-calendar>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				mode: 'range',
				lat: "",
				lng: "",
				listid: "",
				city_text: "", //当前城市信息
				currentAddress: "", //当前位置
				start: "", //年月日
				end: "", //年月日
				startime: "", //开始时间
				endtime: "", //结束时间
				startweek: "", //开始周
				endweek: "", //结束周
				daynum: 1,
				juli:'',
				dataAll: {},
				videourl:[],
				state:0,//控制图片，视频显示 0 图片 1 视频
				pageScrollTop:0,
				showMain:false,
				pageShow:false
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg));
			this.listid = data.id
			this.start = data.start
			this.end = data.end
			this.startime = data.startime
			this.endtime = data.endtime
			this.startweek = data.startweek
			this.endweek = data.endweek
			this.daynum = data.daynum
			this.juli=data.juli
			let storagecity = uni.getStorageSync("storagecity") || null
			if(storagecity){
				this.citytext = storagecity.citytext
				this.lat = storagecity.latitude
				this.lng = storagecity.longitude
				this.cityid = storagecity.cityid
			}
			this.init()
		},
		onPageScroll(e) {
			this.pageScrollTop = e.scrollTop
		},
		methods: {
			gundong(){
				// 假设我们要定位到id为'target'的元素
				const query = uni.createSelectorQuery().in(this);
				query.select('#target').boundingClientRect(data => {
				  if (data) {
				    // 使用uni.pageScrollTo滚动到元素的位置
				    uni.pageScrollTo({
				      scrollTop: data.top +(this.pageScrollTop || 0), // pageScrollTop是页面当前的滚动位置
				      duration: 300 // 动画时长，可根据需要调整
				    });
				  }
				}).exec();
			},
			contactkf(firend_id,type){
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.request('/api/user/addFriends', 'GET', {
					firend_id,
					type
				}).then(res => {
					uni.hideLoading()
					let data = {
						firend_id: firend_id,
						friend_name: this.dataAll.shop.name,
						firend_avatar_text: this.dataAll.shop.logo_text
					}
					if(res.code==1){
						uni.navigateTo({
							url:"/pages_wode/chat?msg=" + encodeURIComponent(JSON.stringify(data))
						})
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
			collect(id){
				httpRequest.request('/api/hotelcl/hotelCollect', 'GET', {
					id: this.listid,
				}, false, false, false).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.dataAll.is_collect = this.dataAll.is_collect?0:1
					}
				})
			},
			init() {
				httpRequest.request('/api/hotelcl/hotelDetail', 'GET', {
					id: this.listid,
				}, false, false, false).then(res => {
					this.pageShow = true
					this.showMain=true
					this.dataAll = res.data
					this.videourl.push(res.data.video_url_text)
				}).catch(err => {
					this.showMain=true
					httpRequest.toast(err.msg);
				})
			},
			goYuDing(id){
				if(!this.startime){
					httpRequest.toast("请选择入住日期")
					return false
				}
				let date = {
					id,
					start:this.start,
					end:this.end,
					startime: this.startime, //开始时间
					endtime: this.endtime, //结束时间
					startweek: this.startweek, //开始周
					endweek: this.endweek, //结束周
					daynum: this.daynum,
				}
				if (!httpRequest.checkIsLogin()) {
				 httpRequest.doLogin();
				 return false;
				}else{
				 uni.navigateTo({
					url: '/pages_lianmengsc/yuding?msg=' + encodeURIComponent(JSON.stringify(date))
				 })
				} 
			},
			// 跳转查看评价
			tzckpj(){
				uni.navigateTo({
					url: '/pages_lianmengsc/quanbupj?type=2&id='+this.listid
				})
			},
			openlocation(){
				let that = this
				uni.openLocation({
				     latitude: Number(that.dataAll.lat),//即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
				     longitude:Number(that.dataAll.lng),//即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
				     name: that.dataAll.name,//即将传到高德或腾讯地图的店铺名称
				     address: that.dataAll.detail,//即将传到高德或腾讯地图的详细地址
				     scale: 18
				})
			},
			// 跳转房间详情
			tzfjxq(id) {
				if(!this.startime){
					httpRequest.toast("请选择入住日期")
					return false
				}
				let date = {
					id,
					start:this.start,
					end:this.end,
					startime: this.startime, //开始时间
					endtime: this.endtime, //结束时间
					startweek: this.startweek, //开始周
					endweek: this.endweek, //结束周
					daynum: this.daynum,
				}
				uni.navigateTo({
					url: '/pages_lianmengsc/fangjianxq?msg=' + encodeURIComponent(JSON.stringify(date))
				})
			},
			// 时间选择确定
			confirm(e) {
				let start = e[0]
				let end = e[e.length - 1]
				this.startime = Number(start[5] + start[6]) + "月" + Number(start[8] + start[9]) + "日" //月日赋值
				this.endtime = Number(end[5] + end[6]) + "月" + Number(end[8] + end[9]) + "日" //月日赋值
				this.start = start
				this.end = end
				this.startweek = this.weekchange(start) //计算周
				this.endweek = this.weekchange(end) //计算周
				this.daynum = this.DateDiff(start, end) //计算间隔天数
				this.show = false
			},
			// 日期初始化
			dateinit() {
				// 今天
				let start = this.date(new Date())
				let end = new Date()
				// 明天
				end.setTime(end.getTime() + 24 * 60 * 60 * 1000);
				end = this.date(end)
				this.start = start
				this.end = end
				this.startime = Number(start[5] + start[6]) + "月" + Number(start[8] + start[9]) + "日" //月日赋值
				this.endtime = Number(end[5] + end[6]) + "月" + Number(end[8] + end[9]) + "日" //月日赋值
				this.startweek = this.weekchange(start) //计算周
				this.endweek = this.weekchange(end) //计算周
				this.daynum = this.DateDiff(start, end) //计算间隔天数
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day
			
				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			// 周转换，此处地date是年月日
			weekchange(date) {
				let weekArrayList = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', ]
				let index = new Date(date).getDay()
				let week = weekArrayList[index]
				return week
			},
			// 计算两个日期之间相差天数
			DateDiff(sDate1, sDate2) {
				//sDate1和sDate2是2006-12-18格式
				var aDate1, aDate2, oDate1, oDate2, iDays;
				aDate1 = sDate1.split("-");
				oDate1 = new Date(aDate1[1] + '/' + aDate1[2] + '/' + aDate1[0]);
				aDate2 = sDate2.split("-");
				oDate2 = new Date(aDate2[1] + '/' + aDate2[2] + '/' + aDate2[0]);
				iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24);
				return iDays
			}
		}
	}
</script>

<style lang="scss" scoped>
	.hhbtn {
		width: 89rpx;
		height: 37rpx;
		border-radius: 37rpx 37rpx 37rpx 37rpx;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #999999;
		border: 2rpx solid #999999;
	}

	.shangj:first-child {
		margin-top: 0;
	}

	.shangj {
		margin-top: 30rpx;
	}

	.huabtn {
		width: 295rpx;
		height: 76rpx;
		border-radius: 120rpx;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
		background-color: #FF9341;
	}

	.zaxd {
		width: 87rpx;
		height: 86rpx;
	}

	.tupian {
		width: 199rpx;
		height: 228rpx;
		border-radius: 9rpx 9rpx 9rpx 9rpx;
	}

	.xhbtn {
		width: 72rpx;
		height: 34rpx;
		background: #E7E7E7;
		border-radius: 17rpx 17rpx 17rpx 17rpx;
		font-size: 22rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.dhicon {
		width: 66.66rpx;
		height: 66.66rpx;
	}

	.ztxhx {
		position: absolute;
		bottom: 6rpx;
		left: 0;
		width: 56rpx;
		z-index: 0;
		height: 9rpx;
		background: #FF9341;
	}

	.block {
		padding: 30rpx 30rpx;
		border-radius: 39rpx 39rpx 0rpx 0rpx;
	}
</style>